package me.caofeng.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import me.caofeng.enums.ItemStatus;

import java.io.IOException;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.util
 * @Description:
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-23 16:15
 * @Version: V1.0
 */
public class JsonItemStatusSerializer extends JsonSerializer<ItemStatus>{
    @Override
    public void serialize(ItemStatus value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
        String json = null;
        switch (value){
            case ON:
                json = "销售中";
                break;
            case OFF:
                json = "已下架";
                break;
            case EDIT:
                json = "编辑中";
                break;
        }
        gen.writeString(json);
    }
}
